//
//  MCDataTool.m
//  TLYL
//
//  Created by MC on 2017/6/20.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCDataTool.h"
#import "MCUserDefinedLotteryCategoriesModel.h"

@implementation MCDataTool

+(void)MC_SaveMarr:(NSArray *)marr withID:(NSString *)IDStr{
    
    //将模型数组转化为字典数组
    NSMutableArray *array=[NSMutableArray array];
    for (int i=0; i<marr.count; i++) {
        MCUserDefinedLotteryCategoriesModel *cellModel=marr[i];
        NSDictionary *dict=cellModel.mj_keyValues;
        [array addObject:dict];
    }
    //保存数组在本地
    NSString * docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES) lastObject];
    
    NSString * fileName = [docDir stringByAppendingPathComponent:MCHomePageLotteryCategoryData];
    
    [array writeToFile:fileName atomically:YES];

    
}

+(NSMutableArray *)MC_GetMarr_withID:(NSString *)IDStr{
    //取出本地的字典数组
    NSString * docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES) lastObject];
    NSString * fileName = [docDir stringByAppendingPathComponent:MCHomePageLotteryCategoryData];
    NSArray * models = [NSArray arrayWithContentsOfFile:fileName];
    //将取出来的字典数组转化为模型数组
    NSMutableArray *arrayModel=[NSMutableArray array];
    for (int i=0; i<models.count; i++) {
        
        NSDictionary *dict=models[i];
        //字典转模型
        MCUserDefinedLotteryCategoriesModel *cellModel=[MCUserDefinedLotteryCategoriesModel mj_objectWithKeyValues:dict];
        [arrayModel addObject:cellModel];
    }

    return arrayModel;
    
}
/*
 * 获取LotteryJSON_CZHelper.json的字典
 */
+(NSDictionary *)MC_GetDic_CZHelper{
    NSData *JSONData_CZHelper = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"LotteryJSON_CZHelper.json" ofType:nil ]];
    NSDictionary*dic_CZHelper = [NSJSONSerialization JSONObjectWithData:JSONData_CZHelper options:NSJSONReadingAllowFragments error:nil];
    return dic_CZHelper;
}
    
/*
 * 获取LotteryJSON_CZ.json的字典
 */
+(NSDictionary *)MC_GetDic_CZ{
    NSData *JSONData_CZ = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"LotteryJSON_CZ.json" ofType:nil ]];
    NSDictionary*dic_CZ = [NSJSONSerialization JSONObjectWithData:JSONData_CZ options:NSJSONReadingAllowFragments error:nil];
    return dic_CZ;
}
    
/*
 * 获取LotteryJSON_WFHelper.json的字典
 */
+(NSDictionary *)MC_GetDic_WFHelper{
    NSData *JSONData_WF = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"LotteryJSON_WFHelper.json" ofType:nil ]];
    
    NSDictionary*dic_WFHelper = [NSJSONSerialization JSONObjectWithData:JSONData_WF options:NSJSONReadingAllowFragments error:nil];
   
    return dic_WFHelper;
}

    

@end
